/**
 * [1013] 将数组分成和相等的三个部分
 *
 * @format
 * @lc app=leetcode.cn id=1013 lang=javascript
 */

// @lc code=start
/**
 * @param {number[]} arr
 * @return {boolean}
 */
var canThreePartsEqualSum = function (arr) {
    const SUM = arr.reduce((a, b) => a + b)
    let [i, j] = [0, arr.length - 1]
    let count = 0
    while (i < j - 1) {
        count += arr[i]
        if (count == SUM / 3) break
        else i++
    }
    count = 0
    while (j > 1) {
        count += arr[j]
        if (count == SUM / 3) break
        else j--
    }
    return i + 1 < j
}
// debugger
// console.log(canThreePartsEqualSum([0, 2, 1, -6, 6, -7, 9, 1, 2, 0, 1]))
// @lc code=end
